import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
import TableControls from '#cpt/temp/TableControls'
import AddEditModal from '#cpt/temp/AddEditModal'
import Confirm from '#cpt/temp/Confirm'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		// 搜索表单列表
		forms : [
			{ label: '状态',		name: 'enabled', width:250, type: 'select', data:[{ name:'待开启', value: '0' },{ name:'已开启', value: '1' },{ name:'禁用', value: '-1' }] },
			{ label: '名称',		name: 'rotate_name' },
		],
		// 提交表单列表
		formData : [
			{ label: '规则名称',			name: 'rotate_name', 	half:true, required:true },
			{ label: '规则描述',			name: 'rotate_desc', 	half:true, required:true },
		]
	}
	
	model = {}
	
	componentDidMount(){
		if(window.isInit){
			this.fetch()
		}
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'rt-rotate-conf/index')
	
	// 表单
	cols = [
		{ title: '编号', 	dataIndex: 'device_number', 	width:150 },
		{ title: '名称', 	dataIndex: 'device_name', 		width:200 },
		{ title: '状态', 	dataIndex: 'device_model', 		width:200 },
		{ title: '描述', 	dataIndex: 'id_code', 			width:200 },
		TableControls.controls.call(this,{ width: 400 })
	]
	// 表格操作按钮
	table_controls = (text,{uuid, device_id, device_name}) => {
		return [
			TableControls.edit.call(this, 'rt-rotate-conf/info', { uuid }),				// 编辑
		]
	}
	// 操作按钮
	controls = () => [
		Controls.add.call(this),			// 添加
		Confirm.call(this, '禁用', 'device/delete', { isKeys: 1 }),
	]
	
	render(){
		return (
			<>
				<Page title='轮转规则列表' controls={this.controls()}>
					{/* 搜索 */}
					{ SearchForm.call(this) }
					{/* 表格 */}
					{ Table.call(this,{isInit:window.isInit}) }
				</Page>
				{/* 添加、编辑 */}
				{ AddEditModal.call(this,{ api: 'rt-rotate-conf/add', editApi:'rt-rotate-conf/edit' }) }
			</>
		)
	}
}

export default Index